<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with garbage collector - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=garbage+collector</link>
      <pubDate>Sun, 08 Aug 2021 17:55:17 +0000</pubDate>
         <description>Tagged with garbage collector - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedgarbage+collector/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Can i create a mask from a shape??</title>
      <link>https://forum.processing.org/two/discussion/27757/can-i-create-a-mask-from-a-shape</link>
      <pubDate>Fri, 13 Apr 2018 17:54:32 +0000</pubDate>
      <dc:creator>RafaelAzevedo</dc:creator>
      <guid isPermaLink="false">27757@/two/discussions</guid>
      <description><![CDATA[<p>Hello!</p>

<p>Can i create a mask from a shape (in this case an ellipse) and change background color but keep the mask untouched?
This ellipse would have its size changed according to the screen and i would have a function windowResized()</p>

<p><img src="https://i.imgur.com/qxNRnXB.jpg" alt="image" /></p>

<p>Thanks! :)</p>
]]></description>
   </item>
   <item>
      <title>Weird memory usage</title>
      <link>https://forum.processing.org/two/discussion/27768/weird-memory-usage</link>
      <pubDate>Sun, 15 Apr 2018 06:15:46 +0000</pubDate>
      <dc:creator>robotman2412</dc:creator>
      <guid isPermaLink="false">27768@/two/discussions</guid>
      <description><![CDATA[<p>i'm making a Universal Turing machine emulator (google it).</p>

<p>it uses ever increasing amounts of memory, not much more to say.</p>

<p>it obviously shouldn't</p>

<p><a rel="nofollow" href="https://pastebin.com/ZNKADezL">https://pastebin.com/ZNKADezL</a> turingmachine.pde</p>

<p><a rel="nofollow" href="https://pastebin.com/isBwGXmD">https://pastebin.com/isBwGXmD</a> GUI.pde (currently unused)</p>

<p><a rel="nofollow" href="https://pastebin.com/guddfXsM">https://pastebin.com/guddfXsM</a> computation.pde</p>

<p><a rel="nofollow" href="https://pastebin.com/nms3733V">https://pastebin.com/nms3733V</a> data.pde</p>

<p>if you look in the main file there is a PGraphics called p.</p>

<p>when i use this to animate writing, the memory usage goes skyhigh, eventually chrashing.</p>

<p>i can't use it for any longer than three minutes like this.</p>
]]></description>
   </item>
   <item>
      <title>Using createGraphics().get() in the draw loop causing memory usage?</title>
      <link>https://forum.processing.org/two/discussion/22039/using-creategraphics-get-in-the-draw-loop-causing-memory-usage</link>
      <pubDate>Mon, 17 Apr 2017 03:03:56 +0000</pubDate>
      <dc:creator>Tsa6</dc:creator>
      <guid isPermaLink="false">22039@/two/discussions</guid>
      <description><![CDATA[<p>Hello, and thank you so much for your time.  I've been working on a project, and found it to be using a ton of memory -- enough that it crashed the program it was being built for.  I spent a couple days poking around to no avail.  I did, however, figure out some of the details of the problem, and was wondering if you kind folks would be able to help me pinpoint a solution.  Anyway, cutting to the chase:</p>

<p>The minimum amount of code I could recreate the problem with was this:</p>

<pre><code>var graphics;

function setup() {
    graphics = createGraphics(1000,1000);
}

function draw() {
    graphics.get();
}
</code></pre>

<p>This produces the expected result, but uses a ton of memory.  Here's the relevant info I could get out of Chrome dev tools:
<img src="http://i.imgur.com/dN3NA9M.png" alt="Task Manager" />
The memory is currently at 1.2 gigs, but I've seen it reach 3 gigs, given enought time.  Either way, that's way too much memory.</p>

<p><img src="https://i.imgur.com/RpD0Iem.png" alt="Timeline" />
The saw tooth pattern continues indefinitely, with the teeth progressively growing slightly larger, but always dropping back down to the same height.
I also checked out the javascript heap snapshot, but it rarely exceeded 10mb, even during peaks.</p>

<p>Based on this, my current theory is that the Graphics.get() method creates excess detached DOM nodes, which build up until garbage collected.  However, I don't know why the spikes get progressively larger, nor do I have any idea as to how to fix it.  If this is a known bug, or common mistake, any further information, solutions, or workarounds would be greatly appreciated.  Thank you again so much for your help!</p>
]]></description>
   </item>
   <item>
      <title>Garbage collection problems? (OutOfMemoryException) [closed]</title>
      <link>https://forum.processing.org/two/discussion/21818/garbage-collection-problems-outofmemoryexception-closed</link>
      <pubDate>Wed, 05 Apr 2017 03:25:09 +0000</pubDate>
      <dc:creator>geek96boolean10</dc:creator>
      <guid isPermaLink="false">21818@/two/discussions</guid>
      <description><![CDATA[<p>So... I've been using Processing to do a little MIDI work. One particular object I was particularly excited to do was re-create the effect of an Animusic-esque marble machine. This, of course, means I have to create my own classes, and in particular, I need a lot of marbles - which is likely the source of my pain.</p>

<p>Running Processing (3.3) with the default memory allocation allows me to render approximately 3000 frames before running out of memory. I then extended the memory to 8 GB, but the result was no different: 3000 frames later, crash.
Now, I know for sure that the only new objects created happen during startup, and when a marble is fired. I realize that it isn't incredibly efficient to generate new marbles every time I need one, but hey. Let the garbage collection do the work, amirite?</p>

<p>Unfortunately, it doesn't seem to like doing that. Even after wholly removing all references to each marble, it appears that they may be still residing in memory. Either that, or I'm doing something else very wrong...</p>

<p>Anyone have ideas as to where this sort of memory build up might be occurring? I certainly make use of a lot of ArrayLists, but again, they are reinstantiated each frame so the garbage collector should be picking them up, no?</p>

<p>[Update 1]
I tried to implement a finalize() call in each marble. I'm now hitting 5000 frames, so it's progress - but the memory buildup continues. This time, I actually got an OpenGL exception drawing a box()... so I'm thinking that's where my problems may lay; I'm drawing two boxes per unit plus two tubes from Shapes3D per frame, 88 times for each note of the keyboard. Is that the problem?</p>

<p>[Update 2]
I re-ran the sketch on a fresh restart, using ~4 GB RAM out of my 16 total. Still set to 8 GB limit, which it hit pretty rapidly. I was able to render about 6000 frames before it started to freeze, and it continued to eek out a couple of frames a minute. The freezes began at frame 6116, and it continued until 6180, at which all progress halted. I stopped the sketch at this point (it had been nearly 10 minutes of inactivity), but I would expect an exception to be thrown if I had let it run.</p>

<p>[Update 3] [Possible fix]
So... bad programming practice, I know, but I added in a explicit System.gc() call every frame. Works beautifully so far - memory has not climbed an inch. Slows down work a lot, so the speed is heavily affected (~8 fps to ~3 fps), but at least this means a stable run. Of course, I assumed it was a memory issue, so we'll see if it gets stuck elsewhere.</p>

<p>[Update 3.1]
No, still climbing, just slowly because it takes some much time to run gc(). Not fixed.</p>

<p>[Update 3.2]
Running it without marble generation is also slowing down and building up memory use. Perhaps this is an issue with the pushMatrix and popMatrix methods?</p>

<p>[Update 3.3]
crashed in event thread due to null
    java.lang.NullPointerException
        at processing.mode.java.runner.Runner$2.run(Runner.java:577)</p>

<p>[CLOSED]
It was my bad; mistake in my code caused objects to be generated non-stop. Still possible GC issue at hand with Shapes3D library, but my issue is solved.</p>
]]></description>
   </item>
   <item>
      <title>PShape Memory Leak - Garbage Collection Pauses</title>
      <link>https://forum.processing.org/two/discussion/1202/pshape-memory-leak-garbage-collection-pauses</link>
      <pubDate>Tue, 12 Nov 2013 08:00:01 +0000</pubDate>
      <dc:creator>Sama</dc:creator>
      <guid isPermaLink="false">1202@/two/discussions</guid>
      <description><![CDATA[<p>It seems that PShapes don't get removed from the memory and instead build up causing long garbage collection / relocation times.</p>

<p>Below is an example of this. The pauses are garbage collections.</p>

<pre><code>void setup () {
   size (200,400,P2D); 
}

void draw() {

  PShape newCells;
     newCells = createShape();  
       newCells.beginShape(TRIANGLES);

         for (int i = 0; i &lt;  2000; i++) {
                newCells.vertex(random(0,width),random(0,height));
                newCells.vertex(random(0,width),random(0,height));
                newCells.vertex(random(0,width),random(0,height));
         }
       newCells.endShape();   

       shape(newCells, 0,0);
 }
</code></pre>

<p>I have looked at the garbage collections in VisualVM and it builds up very quickly and moves memory to Old gen.</p>

<p>The same <strong>doesn't</strong> happen with immediate mode (no PShape)</p>

<p>My questions are:</p>

<p>1) Is this a bug?</p>

<p>2) Would changing GC options help, if so how do you set this up on mac, I am a total novice with Terminal</p>

<p>Edit: Just to clarify, it is clear this is not the way to use PShape, in the context immediate mode or PShape(Group) is appropriate. But my problem is I need to create the shapes in real time, with thousands of triangle each frames, and then repeat the geometry in a mandala (radial symmetry) form.</p>
]]></description>
   </item>
   <item>
      <title>How to disable/manage garbage collection?</title>
      <link>https://forum.processing.org/two/discussion/13293/how-to-disable-manage-garbage-collection</link>
      <pubDate>Tue, 27 Oct 2015 05:30:57 +0000</pubDate>
      <dc:creator>blue_pyro</dc:creator>
      <guid isPermaLink="false">13293@/two/discussions</guid>
      <description><![CDATA[<p>Please critique this post as i'm very new to posting on forums.
I've been jumping between processing to openFrameworks for quite some time trying to develop a decent game engine to work with.  The reason i was using openFrameworks for a while was because i kept getting strange null pointer exceptions that i just couldn't resolve.  I've since moved back to processing because of how difficult it was to create nested classes in c++(especially once i started trying to link them in separate files).  While processing somewhat excels with prototyping in that it doesn't require much linking, i'm facing this null pointer exception once again...  and i think i found the culprit.  I believe it's the garbage collector(gc) done by the JVM.  I can handle raw pointers pretty well when making the game engine but relying on the gc seems to be a pain.  In a past proto game i made; the game objects i used were in a hash table.  I lost the copy of that game but my guess is that the gc cleaned out objects that weren't being used at the time(causing some objects to turn null).  In my current version of the game engine i've not tested out any objects that were hash mapped as of yet however i noticed something which has brought me to the tons of research and eventually these humble forums.</p>

<p>Now that that's out of the way let me demonstrate exactly what i'm talking about.  I'm using processing 2.2.1 though i doubt it would have much to do with this.  Here's the classes I've setup.
The problem is explained below.</p>

<pre><code>Level[] l;
void setup(){
  l = new Level[1];
  for(int i = 0; i &lt; l.length; i++){
    l[i] = new Level();
  }//a single level would work instead of an array but this for 
//when it's desirable to add more than one running level at a time
  size(500,500);
}

void draw(){
  background(0);
  for(int i = 0; i &lt; l.length; i++){
    //l[i].run();
  }
}

void mousePressed(){
  l[1].phys.cl.loadMap();//****added just recently to show the problem****//
//if you remove the above than the problem "seems" to go away but it's just
//cause the string isn't being called on again.
}
//below is spread around different files but i doubt it would matter much
//I've gutted out a lot of the unnecessary code.

class Level{  //level contains all game objects as well as a personal physics engine
  public
  abstract class BPActor{}
  //just a bunch of level objects i was testing
  class dummy extends BPActor{}
  class player extends BPActor{}
  abstract class NPC extends BPActor{}
  Physics phys;
  Level(){  //dont let this class have same method names as it's inner classes
    phys = new Physics(this);  //this is the physics engine which has a reference to the level
  }
}

//here is the physics engine class's file
//note that the physics engine has it's own hash table and loads data to it from the "chunk loader" class.

abstract class PhysicsBlueprint{
  public
  Level rl;
  ChunkLoader cl;

  void build(){
    cl.loadMap();
  }
}



class Physics extends PhysicsBlueprint{
  public

  Physics(Level _l){
    rl = _l;
    cl = new ChunkLoader(this);
    build();
  }
}

//the last file is for a chunk loader class.  this is what takes data from files and loads it into the hash table.

class ChunkLoader{
  public
  String lines[];
  Physics phys;

  ChunkLoader(Physics _p){
    phys = _p;
  }
  void loadMap(){
    lines = loadStrings("../list.txt");//use list.txt instead of ../list.txt if you are using a data folder but the list file is outside it
    println("there are " + lines.length + " lines");
    for (int i = 0; i &lt; lines.length; i++) {
      //println(lines[i]);  //disabled due to file being too big to log.
    }
  }
}  //OK THAT'S IT.
</code></pre>

<p>//the file i referenced was very large for testing purposes.  Maybe the JVM didn't like that.
//however i test with a small file shows the exact same results.</p>

<p>First save this code into a sketch and make sure to include a dummy list.txt with a few lines of dummy text into the saved folder.  The txt file must have more than one line.</p>

<p>Now here's the problem.  If you run this code for about 1 min(resource monitor helps if the file is big enough) and press any key you'll notice a crash with a null pointer exception.  And this points directly to the string called "lines" in the ChunkLoader class.  This tells me that the garbage collector is indeed responsible for the null pointer.  Now to repeat the question.  Can i disable the garbage collector in processing or at least have a full proof easy way to get around this.  If this could happen to a string what's stopping the gc from wrecking my hash table and game objects?  If i can get around this I'll have a decent first game developed with a friend within a month.  If anyone helps me solve this problem i'll likely make all game engines/level editors i create with processing open source.  Other wise i'll have to go back to c++ and openFrameworks.
Apologies for the rambling and am grateful for any help/critique.</p>
]]></description>
   </item>
   </channel>
</rss>